package com.cn.project.controller;

import com.cn.common.pojo.ItemModel;
import com.cn.common.pojo.ResultModel;
import com.cn.project.service.ItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

@Api(tags = "标题信息")
@RestController
@RequestMapping("item")
public class ItemController {
    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String date= DATE_FORMAT.format(new Date());
    @Autowired
    ItemService itemService;
    @ApiOperation("产品标题删除")
    @GetMapping("item")
    public ResultModel item(){
        ResultModel item = itemService.item();
        return item;
    }

    @GetMapping("delete")
    public ResultModel delete(int id){
        ResultModel delete = itemService.delete(id);
        return delete;
    }
    @ApiOperation("修改产品标题")
    @PostMapping("update")
    public ResultModel update(ItemModel itemModel){
        ResultModel update = itemService.update(itemModel);
        return update;
    }
    @ApiOperation("增加产品标题")
    @PostMapping("insert")
    public ResultModel insert(ItemModel itemModel){
        ResultModel insert = itemService.insert(itemModel);
        return insert;
    }
    @ApiOperation("产品标题状态控制")
    @PostMapping(value = "enable")
    public ResultModel enable(int id){
        ResultModel enable = itemService.enable(id);
        return enable;
    }
    @ApiOperation("增加产品标题id查找")
    @GetMapping("findById")
    public ResultModel findById(int id){
        ResultModel findById = itemService.findById(id);
        return findById;
    }
    @ApiOperation("产品标题全部信息")
    @GetMapping("limit")
    public ResultModel limit(ItemModel itemModel,int limit,int page){
        itemModel.setPageNum(page);
        itemModel.setPageSize(limit);
        ResultModel resultModel = itemService.limit(itemModel);
        return resultModel;
    }
}
